package GUI;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

import ModelLayer.*;

public class AssignToOrder extends JFrame {

	private JPanel contentPane;
	private Success su;
	private JList<String> list;
	private Super zuper;
	

	/**
	 * Create the frame.
	 */
	public AssignToOrder(final String s, String or) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 285, 285);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		switch(s){
		case "m": Label("member"); populateList("m"); break;
		case "p": Label("payment type"); populateList("p"); break;
		case "dis": Label("discount"); populateList("dis"); break;
		case "del": Label("delivery type"); populateList("del"); break;
		case "s": Label("staff"); populateList("s"); break;
		}
		
		switch(or){
		case "o": setTitle("Assign to Order"); break;
		case "r": setTitle("Assign to Rent"); break;
		case "dis": setTitle("Assign discount"); break;
		}
		
		JTextField txtSearch = new JTextField();
		txtSearch.setText("search...");
		txtSearch.setBounds(10, 35, 150, 20);
		contentPane.add(txtSearch);
		txtSearch.setColumns(10);
		
		JButton btnSearch = new JButton("Search");
		btnSearch.setBounds(170, 34, 89, 23);
		contentPane.add(btnSearch);
		
		
		list.setBounds(10, 66, 250, 137);
		contentPane.add(list);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				dispose();
			}
		});
		btnCancel.setBounds(10, 214, 89, 23);
		contentPane.add(btnCancel);
		
		JButton btnAssign = new JButton("Assign");
		btnAssign.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				switch(s){
				case "m": zuper.order.setCustomer(Customers.getCustomer(list.getSelectedValue())); break;
				case "p": zuper.order.setPaymentType(PaymentTypes.getPaymentType(list.getSelectedValue())); break;
				case "dis": Label("discount"); populateList("dis"); break;
				case "del": Label("delivery type"); populateList("del"); break;
				case "s": Label("staff"); populateList("s"); break;
				}
				
				dispose();
			}
		});
		btnAssign.setBounds(170, 214, 89, 23);
		contentPane.add(btnAssign);
	}
	
	public void Label(String field){
		JLabel lblCurrentlyAssigned = new JLabel("Currently assigned " + field + ": ");//data!!!
	 	lblCurrentlyAssigned.setBounds(20, 10, 150, 14);
	 	contentPane.add(lblCurrentlyAssigned);
	}
	
	private void populateList(String x)
	{
		if(x=="m")
		{
			String[] c = new String[Customers.getSize()];
			
			for(int i=0;i<Customers.getSize();i++)
			{
				c[i]=String.valueOf(i);
			}
			list = new JList<String>(c);
		}
		else
		{
			if(x=="p")
			{
				String[] c = new String[PaymentTypes.getSize()];
				for(int i=0;i<PaymentTypes.getSize();i++)
				{
					c[i]=String.valueOf(i);
				}
				list = new JList<String>(c);
			}
			else
			{
				if(x=="dis")
				{
					String[] c = new String[Discounts.getSize()];
					
					for(int i=0;i<Discounts.getSize();i++)
					{
						c[i]=String.valueOf(i);
					}
					list = new JList<String>(c);
				}
				else
				{
					if(x=="del")
					{
						String[] c = new String[DeliveryTypes.getSize()];
						
						for(int i=0;i<DeliveryTypes.getSize();i++)
						{
							c[i]=String.valueOf(i);
						}
						list = new JList<String>(c);
					}
					else
					{
						if(x=="s")
						{
							String[] c = new String[Staffs.getSize()];
							
							for(int i=0;i<Staffs.getSize();i++)
							{
								c[i]=String.valueOf(i);
							}
							list = new JList<String>(c);
						}
					}
				}
			}
		}
	}
}


